package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.impl.CategoryBrandServiceImpl;
import com.atguigu.spzx.manager.entity.CategoryBrand;
import com.atguigu.spzx.common.result.Result;
import com.atguigu.spzx.manager.vo.brand.BrandQueryRespVo;
import com.atguigu.spzx.manager.vo.categoryBrand.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * categoryBrandController
 * </p>
 *
 * @author flyduck
 * @since 2023/10/29
 */
@Api(tags = "分类品牌管理接口")
@RestController
@RequestMapping("/admin/product/categoryBrand")
public class CategoryBrandController {

    @Autowired
    private CategoryBrandServiceImpl categoryBrandService;

    @ApiOperation("根据分类id查询对应的品牌数据")
    @GetMapping("/getBrandListByCategoryId/{categoryId}")
    public Result<List<BrandQueryRespVo>> findBrandListByCategoryId(@PathVariable Long categoryId){
        List<BrandQueryRespVo> respVoList =  categoryBrandService.getBrandListByCategoryId(categoryId);
        return Result.ok(respVoList);
    }


    @ApiOperation("根据id删除")
    @DeleteMapping("/deleteCategoryBrandById/{id}")
    public Result<Void> deleteCategoryBrandById(@PathVariable Long id){
        categoryBrandService.deleteCategoryBrandById(id);
        return Result.ok();
    }

    @ApiOperation("根据id查询")
    @GetMapping("/getCategoryBrandById/{id}")
    public Result<CategoryBrandDetailsRespVo> getCategoryBrandById(@PathVariable Long id){
        CategoryBrandDetailsRespVo respVo = categoryBrandService.getCategoryBrandById(id);
        return Result.ok(respVo);
    }

    @ApiOperation("修改")
    @PostMapping("/updateCategoryBrandById")
    public Result updateCategoryBrandById(@RequestBody CategoryBrandUpdateReqVo reqVo){
        categoryBrandService.updateCategoryBrandById(reqVo);
        return Result.ok();
    }

    @ApiOperation("添加")
    @PostMapping("/saveCategoryBrand")
    public Result saveCategoryBrand(@RequestBody CategoryBrandSaveReqVo reqVo){
        categoryBrandService.saveCategoryBrand(reqVo);
        return Result.ok();
    }

    @ApiOperation("条件分页查询")
    @GetMapping("/getCategoryBrandPageByQuery/{page}/{limit}")
    public Result<Page<CategoryBrandQueryRespVo>> getCategoryBrandPageByQuery(@PathVariable Integer page,
                                                                              @PathVariable Integer limit,
                                                                              CategoryBrandQueryReqVo reqVo){
        Page<CategoryBrand> pageParam = new Page<>(page, limit);
        Page<CategoryBrandQueryRespVo> pageModel = categoryBrandService.getCategoryBrandPageByQuery(pageParam,reqVo);
        return Result.ok(pageModel);
    }
}
